import request from './request'
import {passwordHash} from '../utilities/crypto'

export function query ({currentPage = 1, perPage = 10, userName, state} = {}) {
  return request({
    url: '/system/user/userList.do',
    method: 'POST',
    body: {currentPage, perPage, userName, state}
  })
}

export function create ({userName, pwd, userDesc, userRole}) {
  pwd = passwordHash(pwd)
  return request({
    url: '/system/user/addUser.do',
    method: 'POST',
    body: {userName, pwd, userDesc, userRole}
  })
}

export function edit ({id, userName, userRole, pwd, userDesc}) {
  return request({
    url: '/system/user/editUser.do',
    method: 'POST',
    body: {id, userName, userRole, pwd, userDesc}
  })
}

export function forbidden (id, state) {
  return request({
    url: '/system/user/enabledUser.do',
    method: 'POST',
    body: {id, state}
  })
}

export function reset (id, pwd) {
  pwd = passwordHash(pwd)
  return request({
    url: '/system/user/replaceUser.do',
    method: 'POST',
    body: {id, pwd}
  })
}
export function resett (oldP, newP) {
  oldP = passwordHash(oldP)
  newP = passwordHash(newP)
  return request({
    url: '/system/user/updatePwd.do',
    method: 'POST',
    body: {oldPwd: oldP, newPwd: newP}
  })
}

export function queryRole () {
  return request({
    url: '/system/role/selectAllRole.do',
    method: 'POST',
    body: {}
  })
}
